#include "DaterWarningWindow.h"
#include "AnimationWindowTrans.h"
#include "DaterCommon.h"

WarningWindow::WarningWindow(const CEGUI::String& id_name, CEGUI::Window* parent):
BaseWindow(parent)
{
	using namespace CEGUI;

	_root = CEGUI::WindowManager::getSingleton().loadWindowLayout("WarningWindow.layout", id_name);

    _root->setDestroyedByParent(false);

	_name = _root->getName().c_str();

	_type = "free";

    // Do events wire-up
    _root->getChild("WarningWindow/ConfirmButton")->
        subscribeEvent(PushButton::EventClicked, Event::Subscriber(&WarningWindow::handle_CloseButton, this));

	_root->subscribeEvent(FrameWindow::EventCloseClicked,Event::Subscriber(&WarningWindow::handle_CloseButton,this));

	_root->setVisible(false);

	_parent->addChildWindow(_root);
}

WarningWindow::~WarningWindow()
{
    CEGUI::WindowManager::getSingleton().destroyWindow(_root);
}

void WarningWindow::showWindow(std::string title, std::string message)
{
	_root->setText(mbcs_to_utf8(title.c_str()));
	_root->getChild("WarningWindow/WarningMessage")->setText(mbcs_to_utf8(message.c_str()));

	AlphaTransWindow* alphaTransWindow1 = new AlphaTransWindow (_root, "alpha2");
	alphaTransWindow1->start();
	_root->setVisible(true);
	_root->activate();
}

void WarningWindow::hideWindow()
{
	_root->deactivate();
	AlphaTransWindow* alphaTransWindow1 = new AlphaTransWindow (_root, "alpha1");
	alphaTransWindow1->start();
}

bool WarningWindow::handle_CloseButton(const CEGUI::EventArgs& args)
{
	hideWindow();

	return true;
}